class BlogController < ApplicationController
  #  before_filter :check_user  ,:only=>[:new,:my,:edit,:create]
  def index
    @article = Article.find(:all,:order=>"created_at DESC")
  end

  def user
    @user = User.find_by_name(params[:name]) 
    @article = @user.articles
  end

  def edit
    @article = Article.find(params[:id])
  end

  def upload
  end
  def new
  #  render :text=>session[:user]
    @user = check_user
    @article =Article.new
  end
  
  def create
    @user = check_user
    @article = Article.new(params[:article])
    @article.views = 0
    if @user.articles<<@article
      flash[:notice]='create new article success'
      redirect_to :action=>:my
    else
      render :action=>:new
    end
  end
  
  def my
    @user = check_user
    @article =@user.articles
  end

  def show
    @article = Article.find(params[:id])
    views = @article.views+1
    @article.update_attribute("views", views)
  end
end
